package com.wk.jetpackdemo.recyclerview

import android.databinding.BindingAdapter
import android.support.v4.widget.SwipeRefreshLayout
import android.util.Log
import android.widget.ImageView
import com.wk.jetpackdemo.model.BaseViewModel
import com.wk.jetpackdemo.utils.ImageUtil

@BindingAdapter(value = ["url", "avatar"], requireAll = false)
fun bindUrl(imageView: ImageView, url: String?, isAvatar: Boolean?) {
    ImageUtil.load(url, imageView, isAvatar = isAvatar ?: false)
}

@BindingAdapter(value = ["onRefresh"])
fun bindOnRefresh(v: SwipeRefreshLayout, vm: BaseViewModel) {
    v.setOnRefreshListener {
        Log.e("BindingAdapter", "setOnRefreshListener SUCCESS")
        vm.loadData(1)
    }
}